package cn.gz.template;

import org.jdesktop.swingx.VerticalLayout;

import javax.swing.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.List;

public class GenerateIfSpecify extends JDialog {
    private JPanel fullPane;

    public GenerateIfSpecify() {
        setContentPane(fullPane);
        setModal(true);

        // call onCancel() when cross is clicked
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                onCancel();
            }
        });

        // call onCancel() on ESCAPE
        fullPane.registerKeyboardAction(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                onCancel();
            }
        }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("GenerateIfSpecify");
        JPanel contentPane = new GenerateIfSpecify().fullPane;
        frame.setContentPane(contentPane);
        VerticalLayout verticalLayout = new VerticalLayout();
        contentPane.setLayout(verticalLayout);
        List<String> list = new ArrayList<>();
        list.add("id");
        list.add("name");

        for (String s : list) {
            JCheckBox checkBox = new JCheckBox();
            checkBox.setText(s);
            contentPane.add(checkBox);
        }
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    private void onOK() {
        // add your code here
        dispose();
    }

    private void onCancel() {
        // add your code here if necessary
        dispose();
    }

    private void createUIComponents() {
        // TODO: place custom component creation code here
    }
}
